package com.ccrfid.rmc6.repository.business.nightPatrol;

import com.ccrfid.rmc6.entity.business.nightpatrol.NpGroupEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface NpGroupRepository extends Repository<NpGroupEntity, Long> {

    NpGroupEntity getById(Long id);

    List<NpGroupEntity> getAllBy();

    boolean existsById(Long id);

    boolean existsByGroupName(String groupName);

    NpGroupEntity save(NpGroupEntity entity);

    void deleteById(Long id);
//
//    @Query(nativeQuery = true, value =
//            "select * from verify_record WHERE id = " +
//                    "(select MAX(id) from verify_record WHERE id_Card = :idCard)")
//    VerifyRecordEntity findMaxVeriryRecord(@Param("idCard") String idCard);

    @Query(nativeQuery = true, value =
            "select * from np_group where start_time <= :preday and end_time >= :preday")
    List<NpGroupEntity> getPreNpGroup(@Param("preday") String preday);

    @Query(nativeQuery = true, value =
            "select * from np_group where start_time <= :patrolTime and end_time >= :patrolTime and group_name like '% :groupName %'")
    List<NpGroupEntity> getGroup(@Param("groupName") String groupName, @Param("patrolTime") String patrolTime);


    List<NpGroupEntity> getAllByGroupNameLikeAndStartTimeLessThanEqualAndEndTimeGreaterThanEqual(String groupName, Date startTime, Date endTime);
//    List<NpGroupEntity> getAllByGroupNameLikeAndStartTimeBeAndEndTimeAfter(String groupName, Date startTime ,Date endTime);
}
